<?php
class PublicController extends Zendvn_Controller_Action{
    
    //Mang tham so nhan duoc o moi action
    protected $_arrParam;

    //Duong dan cua controller
    protected $_currentController;
    
    //Duong dan cua Action chinh
    protected $_actionMain;
	
    protected $_namespace;


    public function init() {
        //Mang tham so nhan duoc o moi action
        $this->_arrParam    =   $this->_request->getParams();
        
        //Duong dan cua controller
        $this->_currentController   =   '/' . $this->_arrParam['module'] 
                                      . '/' . $this->_arrParam['controller'];
        
        //Duong dan cua Action chinh
        $this->_actionMain  =   $this->_currentController . '/index';
        
        //Truyen ra view
        $this->view->arrParam   =   $this->_arrParam;
        $this->view->currentController  =   $this->_currentController ;
        $this->view->actionMain  =   $this->_actionMain;
        
        $template_path  =   TEMPLATE_PATH . "/admin/system";
        $this->loadTemplate($template_path , 'template.ini', 'public');
    }
    
    public function errorAction() {
        $this->view->Title = 'Message: Error';
        $this->view->headTitle($this->view->Title, true);
        $error[] = 'Chức năng này không tồn tại';
        $this->view->messageError = $error;
    }
    
    public function noAccessAction() {
        $this->view->Title = 'Message: No Access';
        $this->view->headTitle($this->view->Title, true);
        $error[] = 'Bạn không có quyền truy cập vào chức năng này';
        $this->view->messageError = $error;
        $this->_helper->viewRenderer('error');
    }
    
    public function loginAction() {
        $this->view->Title = 'Login';
        $this->view->headTitle($this->view->Title, true);
        if($this->_request->isPost()){
            $auth = new Zendvn_System_Auth();
            if($auth->login($this->_arrParam)){
                $info = New Zendvn_System_Info();
                $info->createInfo();
                $this->_redirect('default/index/index');
            }else{
                $error[] = $auth->getError();
                $this->view->messageError = $error;
            }
        }
    }
    
    public function logoutAction() {
        $this->view->Title = 'Log out';
        $this->view->headTitle($this->view->Title, true);
        $auth = new Zendvn_System_Auth();
        $auth->logout();
        
        
        $link = $this->view->baseUrl('/default/index/index');
        $this->view->Notes = 'Bạn đã thoát khỏi hệ thống.'
                    . '<a href="'. $link .'">Nhấn vào đây để quay lại trang chủ</a>';
        //$this->view->messageError = $error;
        //$this->_helper->viewRenderer('error');
    }
}
